package cn.attackme.myuploader.dao;

import cn.attackme.myuploader.dao.provider.IconProvider;
import cn.attackme.myuploader.model.Icon;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface IconMapper {
    /**
     * 通过主键获取一行数据
     * @return
     */
    @Select({"select * from T_ICON_LIBRARY where id = #{id}"})
    Icon getById(String id);
    /**
     * 根据名称来获取图标信息
     * @param name
     * @return
     */
    @Select({"select * from T_ICON_LIBRARY where name = #{name}"})
    Icon getIconByName(String name);

    /**
     * 插入一行数据
     * @param file
     * @return
     */
    @Insert({"insert into T_ICON_LIBRARY(id,name,md5,iconImage,uploadtime) values(uuid(),#{name},#{md5},#{iconImage},#{uploadTime})"})
    Integer save(Icon file);

    /**
     * 更新一行数据
     * @param icon
     * @return
     */
    @UpdateProvider(type= IconProvider.class, method = "updateIcon")
    Integer updateIcon(Icon icon);

    @Select({"delete from T_ICON_LIBRARY where id = #{id}"})
    Integer deleteById(String id);

    /**
     * 根据一个或多个属性获取File
     * @param icon
     * @return
     */
    @SelectProvider(type= IconProvider.class, method = "getByIcon")
    Icon getByIcon(Icon icon);

}
